package com.karry.yl.web.system;

import com.baomidou.mybatisplus.enums.SqlLike;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.karry.yl.domain.system.Area;
import com.karry.yl.domain.system.City;
import com.karry.yl.domain.system.Town;
import com.karry.yl.domain.system.Village;
import com.karry.yl.service.system.AreaService;
import com.karry.yl.service.system.CityService;
import com.karry.yl.service.system.TownService;
import com.karry.yl.service.system.VillageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class AddressController {
    @Autowired
    private CityService cityService;
    @Autowired
    private AreaService areaService;
    @Autowired
    private TownService townService;
    @Autowired
    private VillageService villageService;

    /**
     * 根据省Id获取市Id
     * @param pId
     * @return
     */
    @RequestMapping("/city")
    public List<City> cityList(String pId){
        return cityService.selectList(new EntityWrapper<City>().like("id", pId.substring(0,2),SqlLike.RIGHT));
    }

    /**
     * 根据市Id获取区县
     * @param pId
     * @return
     */
    @RequestMapping("/area")
    public List<Area> areaList(String pId){
        return areaService.selectList(new EntityWrapper<Area>().like("id", pId.substring(0,4),SqlLike.RIGHT));
    }


    /**
     * 根据区县Id获取
     * @param pId
     * @return
     */
    @RequestMapping("/town")
    public List<Town> townList(String pId){
        return townService.selectList(new EntityWrapper<Town>().like("id", pId.substring(0,6),SqlLike.RIGHT));
    }


    /**
     * 根据城镇Id获取  村和街道
     * @param pId
     * @return
     */
    @RequestMapping("/village")
    public List<Village> villageList(String pId){
        return villageService.selectList(new EntityWrapper<Village>().like("id", pId.substring(0,9),SqlLike.RIGHT));
    }

}
